package com.hqyj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hqyj.pojo.Exam;
import com.hqyj.dao.ExamMapper;
import com.hqyj.service.IExamService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author rock
 * @since 2021-11-22
 */
@Service
public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IExamService {

    @Autowired
    private ExamMapper examMapper;
    @Override
    public HashMap<String, Object> select(Exam exam) {
        HashMap<String, Object> map = new HashMap<>();
        // 分页对象
        Page<Exam> examPage = new Page<Exam>(exam.getPage(),exam.getRow());

        // 条件构造器
        QueryWrapper<Exam> examQueryWrapper = new QueryWrapper<>();
        // 获取分页结果集
        Page<Exam> page = examMapper.selectPage(examPage, examQueryWrapper);

        // 获取返回的分页结果集对象
        map.put("info","success");
        map.put("list",page.getRecords());
        map.put("total",page.getTotal());

        return map;
    }

    @Override
    public HashMap<String, Object> add(Exam exam) {
        HashMap<String ,Object> map=new HashMap<>();
        //新增
        int num=examMapper.insert(exam);
        if (num>0){
            map.put("info","保存成功");

        }else {
            map.put("info","保存失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> update(Exam exam) {
        HashMap<String ,Object> map=new HashMap<>();
        //新增
        int num=examMapper.updateById(exam);
        if (num>0){
            map.put("info","保存成功");

        }else {
            map.put("info","保存失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> del(Integer iexamId) {
        HashMap<String ,Object> map=new HashMap<>();
        //新增
        int num=examMapper.deleteById(iexamId);
        if (num>0){
            map.put("info","保存成功");

        }else {
            map.put("info","保存失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> selectStudent(Integer studentNumber) {
        HashMap<String ,Object> map=new HashMap<>();
        //新增
        int num=examMapper.selectStudent(studentNumber);
        if (num>0){
            map.put("info","保存成功");

        }else {
            map.put("info","保存失败");
        }
        return map;
    }

}
